
package jpamodel;

import java.io.Serializable;
import java.time.LocalDate;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Joseph
 */
@Entity
@Table(name = "OwnedWare")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "OwnedWare.findAll", query = "SELECT o FROM OwnedWare o"),
    @NamedQuery(name = "OwnedWare.findByProdID", query = "SELECT o FROM OwnedWare o WHERE o.prodID = :prodID"),
    @NamedQuery(name = "OwnedWare.findByName", query = "SELECT o FROM OwnedWare o WHERE o.name = :name"),
    @NamedQuery(name = "OwnedWare.findByPurchasePrice", query = "SELECT o FROM OwnedWare o WHERE o.purchasePrice = :purchasePrice"),
    @NamedQuery(name = "OwnedWare.findBySoldPrice", query = "SELECT o FROM OwnedWare o WHERE o.soldPrice = :soldPrice"),
    @NamedQuery(name = "OwnedWare.findByDateIn", query = "SELECT o FROM OwnedWare o WHERE o.dateIn = :dateIn"),
    @NamedQuery(name = "OwnedWare.findByDateOut", query = "SELECT o FROM OwnedWare o WHERE o.dateOut = :dateOut")})
public class OwnedWare implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "prod_ID")
    private Integer prodID;
    @Column(name = "name")
    private String name;
    @Column(name = "purchasePrice")
    private Integer purchasePrice;
    @Column(name = "soldPrice")
    private Integer soldPrice;
    @Column(name = "dateIn")
    @Temporal(TemporalType.TIMESTAMP)
    private LocalDate dateIn;
    @Column(name = "dateOut")
    @Temporal(TemporalType.TIMESTAMP)
    private LocalDate dateOut;
    @JoinColumn(name = "fk_category", referencedColumnName = "cat_ID")
    @ManyToOne(optional = false)
    private Category category;

    public OwnedWare() {
    }

    public OwnedWare(Integer prodID) {
        this.prodID = prodID;
    }

    public Integer getProdID() {
        return prodID;
    }

    public void setProdID(Integer prodID) {
        this.prodID = prodID;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getPurchasePrice() {
        return purchasePrice;
    }

    public void setPurchasePrice(Integer purchasePrice) {
        this.purchasePrice = purchasePrice;
    }

    public Integer getSoldPrice() {
        return soldPrice;
    }

    public void setSoldPrice(Integer soldPrice) {
        this.soldPrice = soldPrice;
    }

    public LocalDate getDateIn() {
        return dateIn;
    }

    public void setDateIn(LocalDate dateIn) {
        this.dateIn = dateIn;
    }

    public LocalDate getDateOut() {
        return dateOut;
    }

    public void setDateOut(LocalDate dateOut) {
        this.dateOut = dateOut;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (prodID != null ? prodID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof OwnedWare)) {
            return false;
        }
        OwnedWare other = (OwnedWare) object;
        return !((this.prodID == null && other.prodID != null) || (this.prodID != null && !this.prodID.equals(other.prodID)));
    }

    @Override
    public String toString() {
        return "jpamodel.OwnedWare[ prodID=" + prodID + " ]";
    }

    public boolean isUnsold() {
        return dateOut == null;
    }

    public SimpleObjectProperty<LocalDate> dateInProperty() {
        return new SimpleObjectProperty<>(dateIn);
    }

    public SimpleObjectProperty<LocalDate> dateOutProperty() {
        return new SimpleObjectProperty<>(dateOut);
    }

    public SimpleIntegerProperty soldPriceProperty() {
        return new SimpleIntegerProperty(soldPrice);
    }
    
    public SimpleIntegerProperty purchasePriceProperty() {
        return new SimpleIntegerProperty(purchasePrice);
    }
    
    public SimpleStringProperty nameProperty() {
        return new SimpleStringProperty(name);
    }
    
}
